package com.lijinjiang.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName Demo01
 * @Description TODO
 * @Author Li
 * @Date 2022/9/25 9:22
 * @ModifyDate 2022/9/25 9:22
 * @Version 1.0
 */
@WebServlet("/demo01")
public class Demo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Response Demo01 doGet...");

        // 重定向
        /*// 1.设置响应状态码 302
        response.setStatus(302);
        // 2.设置响应头 Location
        response.setHeader("Location","/P12_Response/demo02");*/

        // 简化方式完成重定向
        String contextPath = request.getContextPath(); // 获取虚拟路径
        response.sendRedirect(contextPath + "/demo02");
        //response.sendRedirect("https://www.baidu.com");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        super.doPost(request, response);
    }
}
